<?php

class nearbygoodses{
public function index(){
$catalog_id = intval($GLOBALS['request']['catalog_id']);
$city_id = intval($GLOBALS['request']['city_id']);
$page = intval($GLOBALS['request']['page']);
$keyword = strim($GLOBALS['request']['keyword']);
$page=$page==0?1:$page;
$ytop = $latitude_top = floatval($GLOBALS['request']['latitude_top']);
$ybottom = $latitude_bottom = floatval($GLOBALS['request']['latitude_bottom']);
$xleft = $longitude_left = floatval($GLOBALS['request']['longitude_left']);
$xright = $longitude_right = floatval($GLOBALS['request']['longitude_right']);
$ypoint =  $m_latitude = doubleval($GLOBALS['request']['m_latitude']);
$xpoint = $m_longitude = doubleval($GLOBALS['request']['m_longitude']);
$page_size = PAGE_SIZE;
$limit = (($page-1)*$page_size).','.$page_size;
if($keyword)
{
$kws_div = div_str($keyword);
foreach($kws_div as $k=>$item)
{
$kws[$k] = str_to_unicode_string($item);
}
$ukeyword = implode(' ',$kws);
$condition ="  (match(tag_match,name_match,locate_match,deal_cate_match) against('".$ukeyword."' IN BOOLEAN MODE)) and ";
}
$condition.=' buy_type<>1 and is_lottery = 0 ';
if($xpoint>0)
{
$pi = 3.14159265;
$r = 6378137;
$field_append = ", (ACOS(SIN(($ypoint * $pi) / 180 ) *SIN((ypoint * $pi) / 180 ) +COS(($ypoint * $pi) / 180 ) * COS((ypoint * $pi) / 180 ) *COS(($xpoint * $pi) / 180 - (xpoint * $pi) / 180 ) ) * $r) as distance ";
if($condition!='')
$condition.=' and ';
$condition.= " ypoint > $ybottom and ypoint < $ytop and xpoint > $xleft and xpoint < $xright ";
$order = ' distance asc ';
}
else
{
$field_append = '';
$order = 'sort desc ';
}
$deals = m_get_deal_list($limit,$catalog_id,$city_id,array(DEAL_ONLINE),$condition,$order,0,$field_append);
$list = $deals['list'];
$count= $deals['count'];
$page_total = ceil($count/$page_size);
$root = array();
$root['return'] = 1;
$goodses = array();
foreach($list as $item)
{
$goods = getGoodsArray($item);
$goods['distance'] = round($goods['distance']);
$goodses[] = $goods;
}
$root['item'] = $goodses;
$root['page'] = array('page'=>$page,'page_total'=>$page_total);
output($root);
}
}
?>